/**
 * @author ckf
 * @create 2018 09 12 16:35
 * @desc
 **/
import java.util.Scanner;
public class zz {





        public static void main(String[] args) {
            String[] names = new String[4];
            String[] dishMegs = new String[4];
            int[] times = new int[4];
            String[] addresses = new String[4];
            int[] states = new int[4];
            double[] sumPrices = new double[4];

            names[0] = "张萌";
            dishMegs[0] = "红烧带鱼2份";
            times[0] = 12;
            addresses[0] = "天成路207号";
            sumPrices[0] = 76.0;
            states[0] = 1;

            names[1] = "张晴";
            dishMegs[1] = "鱼香肉丝2份";
            times[1] = 12;
            addresses[1] = "天成路207号";
            sumPrices[1] = 45.0;
            states[1] = 0;

            String[] dishNames = { "红烧带鱼", "鱼香肉丝", "肉末茄子" };
            double[] prices = new double[] { 25.0, 15.0, 12.0 };
            int[] praiseNums = new int[3];

            Scanner input = new Scanner(System.in);
            int num = -1;
            boolean isExit = false;
            System.out.println("欢迎使用吃货联盟系统");
            do {
                System.out.println("**********************");
                System.out.println("1、我要订餐");
                System.out.println("2、查看菜袋");
                System.out.println("3、签收订单");
                System.out.println("4、删除订单");
                System.out.println("5、我要点赞");
                System.out.println("6、退出系统");
                System.out.println("**********************");
                System.out.println("请选择：");
                int choose = input.nextInt();
                switch (choose) {
                    case 1:
                        System.out.println("***我要订餐***");
                        boolean isAdd = false;
                        for (int j = 0; j < names.length; j++) {
                            if (names[j] == null) {
                                isAdd = true;
                                System.out.print("请输入订餐人姓名：");
                                names[j] = input.next();
                                System.out.println("序号" + "\t" + "菜名" + "\t" + "单价" + "\t" + "点赞数");
                                for (int i = 0; i < dishNames.length; i++) {
                                    System.out.println((i + 1) + "\t" + dishNames[i] + "\t" + prices[i] + "\t" + praiseNums[i]);
                                }
                                System.out.print("请选择您要点的菜品编号：");
                                int chooseDish = input.nextInt();
                                System.out.print("请选择你要点的份数：");
                                int number = input.nextInt();
                                String dishMeg = dishNames[chooseDish - 1] + " " + number + "份";
                                double sumPrice = prices[chooseDish - 1] * number;
                                double delicharge = (sumPrice >= 50) ? 0 : 5;
                                System.out.print("请输入送餐时间（送餐时间是10点至20点间整点送餐）");
                                int time = input.nextInt();
                                while (time < 10 || time > 20) {
                                    System.out.println("您的输入有误，请输入10-20间的整数！");
                                    time = input.nextInt();
                                }
                                System.out.print("请输入送餐地址：");

                                String address = input.next();
                                System.out.println("恭喜您订餐成功！");
                                System.out.println("您订的是：" + dishMeg);
                                System.out.println("送餐时间：" + time);
                                System.out.println("餐费：" + sumPrice + "元，" + "送餐费：" + delicharge + "元，" + "总计："
                                        + (sumPrice + delicharge) + "元");
                                dishMegs[j] = dishMeg;
                                times[j] = time;
                                addresses[j] = address;
                                sumPrices[j] = sumPrice + delicharge;
                                break;
                            }

                        }
                        if (!isAdd) {
                            System.out.println("对不起，您的菜单已满！");
                        }

                        break;
                    case 2:
                        System.out.println("***查看菜袋***");
                        System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t送餐地址\t\t总金额\t订单状态");
                        for (int i = 0; i < names.length; i++) {
                            if (names[i] != null) {
                                String state = (states[i] == 0) ? "已预订" : "已完成";
                                String date = times[i] + "点";
                                String sumPrice = sumPrices[i] + "元";

                                System.out.println((i + 1) + "\t" + names[i] + "\t" + dishMegs[i] + "\t\t" + date + "\t"
                                        + addresses[i] + "\t\t" + sumPrice + "\t" + state);

                            }
                        }
                        break;
                    case 3:
                        System.out.println("***签收订单***");
                        boolean isSignFind = false;
                        System.out.print("请选择要签收的订单序号：");
                        int signOrderId = input.nextInt();
                        for (int i = 0; i < names.length; i++) {
                            if (names[i] != null && states[i] == 0 && signOrderId == i + 1) {
                                states[i] = 1;
                                System.out.println("订单签收成功！");
                                isSignFind = true;
                            } else if (names[i] != null && states[i] == 1 && signOrderId == i + 1) {
                                System.out.println("您选择的订单已完成签收，不能再次签收！");
                                isSignFind = true;
                            }

                        }
                        if (!isSignFind) {
                            System.out.println("您选择的订单不存在！");
                        }
                        break;
                    case 4:
                        System.out.println("***删除订单***");
                        boolean isDelFind = false;
                        System.out.print("请输入要删除的订单序号：");
                        int delId = input.nextInt();
                        for (int i = 0; i < names.length; i++) {
                            if (names[i] != null && states[i] == 1 && delId == i + 1) {
                                for (int j = delId - 1; j < names.length - 1; j++) {
                                    names[j] = names[j + 1];
                                    dishMegs[j] = dishMegs[j + 1];
                                    times[j] = times[j + 1];
                                    addresses[j] = addresses[j + 1];
                                    sumPrices[j] = sumPrices[j + 1];
                                }
                                int endIndex = names.length - 1;
                                names[endIndex] = null;
                                dishMegs[endIndex] = null;
                                times[endIndex] = 0;
                                addresses[endIndex] = null;
                                states[endIndex] = 0;
                                sumPrices[endIndex] = 0;
                                System.out.println("删除订单成功！");
                                break;
                            } else if (names[i] != null && states[i] == 0 && delId == i + 1) {
                                System.out.println("您选择的订单未签收，不能删除！");
                                isDelFind = true;
                                break;
                            }
                        }
                        if (isDelFind) {
                            System.out.println("您要删除的订单不存在！");
                        }

                        break;
                    case 5:
                        System.out.println("***我要点赞***");
                        System.out.println("序号" + "\t" + "菜名" + "\t" + "单价");
                        for (int i = 0; i < dishNames.length; i++) {
                            String price = prices[i] + "元";
                            String praiseNum = (praiseNums[i]) > 0 ? praiseNums[i] + "赞" : "";
                            System.out.println((i + 1) + "\t" + dishNames[i] + "\t" + price + "\t" + praiseNum);
                        }
                        System.out.print("请选择您要点赞的菜品序号：");
                        int praiseNum = input.nextInt();
                        praiseNums[praiseNum - 1]++;
                        System.out.println("点赞成功！");
                        break;
                    case 6:
                        isExit = true;
                        break;

                }
                if (!isExit) {
                    System.out.print("请输入0返回");
                    num = input.nextInt();
                } else {
                    break;
                }
            } while (num == 0);
            System.out.print("感谢使用本系统！");
        }

    }


